package com.mes.basicdata.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

/**
 * <p>
 * 检验对象，对应着b_operationcheck表
 * </p>
 * 
 * <p>
 * Created on 2017-03-18
 * </p>
 * 
 * @author lcs
 * 
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "B_OPERATIONCHECK")
@BatchSize(size=10)
@Lazy(value=true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class OperationMeasurement extends BasicModel implements Serializable {
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUEID",scale=0)
	private String uniqueId;

	// 工序
	@Column(name="OPUID")
	private String operationUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="OPUID",insertable=false,updatable=false)
	private Operation operation;
	
	// 工艺（现在这个属性基本不维护）
	@Column(name="ROUTING")
	private String routingUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ROUTING",insertable=false,updatable=false)
	private Routing routing;
	
	// 测量基准
	@Column(name="MEASUREBASE")
	private String measureBase;
	
	// 尺寸编号
	@Column(name="FIELDID")
	private String measurementNumber;
	
	// 尺寸排序号
	@Column(name="FIELDORDER",precision=10,scale=0)
	private Integer measurementSeq;
	
	// 尺寸类型
	@Column(name="FIELDTYPE")
	private String measurementType;
	//many-to-one
//	@ForeignKey(name="null")
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumnsOrFormulas(value={
//			@JoinColumnOrFormula(column=@JoinColumn(name="FIELDTYPE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
//			@JoinColumnOrFormula(formula=@JoinFormula(value="'pmitype'", referencedColumnName="TYPESNAME"))
//	})
//	private TypesData measurementTypeDesc;
	
	// 标准值
	@Column(name="STANDARDVALUE",length=50)
	private String standardValue;
	
	// spc标准值
	@Column(name="SPCSTANDARDVALUE",precision=25)
	private Float spcStandardValue;
	
	// 单位
	@Column(name="UOM",length=50)
	private String uom;
	
	// 上限
	@Column(name="UBOUND",precision=25,scale=3)	
	private Float ubound;
	// 下限
	@Column(name="LBOUND",precision=25,scale=3)
	private Float lbound;
	
	// 上下限单位
	@Column(name="BOUNDUOM",length=50)
	private String boundUom;
	
	// 是否关键尺寸
	@Column(name="ISKEYFIELD",precision=2,scale=0)
	private Boolean isKeyMeasurement;

	// 是否需要采集
	@Column(name = "ISNEEDCOLLECT")
	public Boolean isNeedCollect;

	// 是否需要统计
	@Column(name = "IS_NEED_STATISTIC")
	public Boolean isNeedStatistic;
	
	// 是否提交检验
	@Column(name="ISSUBMITCHECK",precision=2,scale=0)
	private Boolean isSubmitCheck;

	// 横轴
	@Column(name="X_AXIS",length=100)
	private String xAxis;
	
	// 上偏差极限百分比
	@Column(name="UP_LIMIT_PERCENT")
	private Float upperLimitPercent;
		
	// 下偏差极限百分比
	@Column(name="LOW_LIMIT_PERCENT")
	private Float lowerLimitPercent;
	
	// 使用刀具
	@Column(name="CUTTERUID",length=50)
	private String cutterItemUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CUTTERUID",insertable=false,updatable=false)
	private Cutter cutter;
	
	// 使用量具
	@Column(name="MEASUREUID",length=50)
	private String measurerItemUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MEASUREUID",insertable=false,updatable=false)
	private Measurer measurer;
	
	// 尺寸特征
	@Column(name="FEATURE",length=50)
	private String feature;
	
	// 检验内容
	@Column(name="CHECK_CONTENT",length=2000)
	private String checkContent;
	
	// 检验图示
	@Column(name="CHECK_PIC",length=50)
	private String checkPic;
	
//	// 标记xml
//	@Column(name="SFMARKUPXML")
//	private String markupXML;
//	
//	@Column(name="TOOL",length=50)
//	private String toolUid;
//
//	// 输入标志
//	@Column(name="FLAGINPUT",precision=2,scale=0)
//	private Integer flagInput;
//	
//	// 检验信息分类
//	@Column(name="CHECKINFOTYPE")
//	private String checkInfoType;
	
	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uniqueId;
	}
	@Override
	public void setUuid(String uniqueId) {
		// TODO Auto-generated method stub
		this.uniqueId = uniqueId;
	}

	
	public String getOperationUid() {
		return operationUid;
	}

	public void setOperationUid(String operationUid) {
		this.operationUid = operationUid;
	}

	public Operation getOperation() {
		return operation;
	}

	public void setOperation(Operation operation) {
		this.operation = operation;
	}

	public String getRoutingUid() {
		return routingUid;
	}

	public void setRoutingUid(String routingUid) {
		this.routingUid = routingUid;
	}

	public Routing getRouting() {
		return routing;
	}

	public void setRouting(Routing routing) {
		this.routing = routing;
	}

	public String getMeasureBase() {
		return measureBase;
	}

	public void setMeasureBase(String measureBase) {
		this.measureBase = measureBase;
	}

	public String getMeasurementNumber() {
		return measurementNumber;
	}

	public void setMeasurementNumber(String measurementNumber) {
		this.measurementNumber = measurementNumber;
	}

	public Integer getMeasurementSeq() {
		return measurementSeq;
	}

	public void setMeasurementSeq(Integer measurementSeq) {
		this.measurementSeq = measurementSeq;
	}

	public String getMeasurementType() {
		return measurementType;
	}

	public void setMeasurementType(String measurementType) {
		this.measurementType = measurementType;
	}

//	public TypesData getMeasurementTypeDesc() {
//		return measurementTypeDesc;
//	}
//
//	public void setMeasurementTypeDesc(TypesData measurementTypeDesc) {
//		this.measurementTypeDesc = measurementTypeDesc;
//	}

	public String getStandardValue() {
		return standardValue;
	}

	public void setStandardValue(String standardValue) {
		this.standardValue = standardValue;
	}

	public Float getSpcStandardValue() {
		return spcStandardValue;
	}

	public void setSpcStandardValue(Float spcStandardValue) {
		this.spcStandardValue = spcStandardValue;
	}

	public String getUom() {
		return uom;
	}

	public void setUom(String uom) {
		this.uom = uom;
	}

	public Float getUbound() {
		return ubound;
	}

	public void setUbound(Float ubound) {
		this.ubound = ubound;
	}

	public Float getLbound() {
		return lbound;
	}

	public void setLbound(Float lbound) {
		this.lbound = lbound;
	}

	public String getBoundUom() {
		return boundUom;
	}

	public void setBoundUom(String boundUom) {
		this.boundUom = boundUom;
	}

	public Boolean getIsKeyMeasurement() {
		return isKeyMeasurement;
	}
	public void setIsKeyMeasurement(Boolean isKeyMeasurement) {
		this.isKeyMeasurement = isKeyMeasurement;
	}
	
	public Boolean getIsSubmitCheck() {
		return isSubmitCheck;
	}
	public void setIsSubmitCheck(Boolean isSubmitCheck) {
		this.isSubmitCheck = isSubmitCheck;
	}
	public String getCutterItemUid() {
		return cutterItemUid;
	}

	public void setCutterItemUid(String cutterItemUid) {
		this.cutterItemUid = cutterItemUid;
	}

	public Cutter getCutter() {
		return cutter;
	}

	public void setCutter(Cutter cutter) {
		this.cutter = cutter;
	}

	public String getMeasurerItemUid() {
		return measurerItemUid;
	}

	public void setMeasurerItemUid(String measurerItemUid) {
		this.measurerItemUid = measurerItemUid;
	}

	public Measurer getMeasurer() {
		return measurer;
	}

	public void setMeasurer(Measurer measurer) {
		this.measurer = measurer;
	}

	public String getFeature() {
		return feature;
	}

	public void setFeature(String feature) {
		this.feature = feature;
	}

	public String getCheckContent() {
		return checkContent;
	}

	public void setCheckContent(String checkContent) {
		this.checkContent = checkContent;
	}

	public void setCheckPic(String checkPic) {
		this.checkPic = checkPic;
	}

	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof OperationMeasurement))
			return false;
		OperationMeasurement castOther = (OperationMeasurement) other;

		return ((this.getOperationUid() == castOther.getOperationUid()) || (this
				.getOperationUid() != null
				&& castOther.getOperationUid() != null && this
				.getOperationUid().equals(castOther.getOperationUid())))
				&& ((this.getMeasurementNumber() == castOther.getMeasurementNumber()) || (this
						.getMeasurementNumber() != null
						&& castOther.getMeasurementNumber() != null && this.getMeasurementNumber()
						.equals(castOther.getMeasurementNumber())));
	}

	public int hashCode() {
		int result = 17;

		result = 37
				* result
				+ (getOperationUid() == null ? 0 : this.getOperationUid()
						.hashCode());
		result = 37 * result
				+ (getMeasurementNumber() == null ? 0 : this.getMeasurementNumber().hashCode());
		return result;
	}

	public String getCheckPic() {
		return checkPic;
	}
	public String getUniqueId() {
		return uniqueId;
	}
	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}
	public Boolean getIsNeedCollect() {
		return isNeedCollect;
	}
	public void setIsNeedCollect(Boolean isNeedCollect) {
		this.isNeedCollect = isNeedCollect;
	}
	public Boolean getIsNeedStatistic() {
		return isNeedStatistic;
	}
	public void setIsNeedStatistic(Boolean isNeedStatistic) {
		this.isNeedStatistic = isNeedStatistic;
	}
	public String getXAxis() {
		return xAxis;
	}
	public void setXAxis(String xAxis) {
		this.xAxis = xAxis;
	}
	public Float getUpperLimitPercent() {
		return upperLimitPercent;
	}
	public void setUpperLimitPercent(Float upperLimitPercent) {
		this.upperLimitPercent = upperLimitPercent;
	}
	public Float getLowerLimitPercent() {
		return lowerLimitPercent;
	}
	public void setLowerLimitPercent(Float lowerLimitPercent) {
		this.lowerLimitPercent = lowerLimitPercent;
	}


}
